package com.luke.base.service.impl;

import java.util.List;

import com.luke.common.config.LuKeConfig;
import com.luke.common.constant.Constants;
import com.luke.common.utils.file.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.luke.base.mapper.LkVehicleMapper;
import com.luke.base.domain.LkVehicle;
import com.luke.base.service.ILkVehicleService;

/**
 * 车型管理Service业务层处理
 * 
 * @author luke
 * @date 2021-05-30
 */
@Service
public class LkVehicleServiceImpl implements ILkVehicleService 
{
    @Autowired
    private LkVehicleMapper lkVehicleMapper;

    /**
     * 查询车型管理
     * 
     * @param id 车型管理ID
     * @return 车型管理
     */
    @Override
    public LkVehicle selectLkVehicleById(Long id)
    {
        return lkVehicleMapper.selectLkVehicleById(id);
    }

    /**
     * 查询车型管理列表
     * 
     * @param lkVehicle 车型管理
     * @return 车型管理
     */
    @Override
    public List<LkVehicle> selectLkVehicleList(LkVehicle lkVehicle)
    {
        return lkVehicleMapper.selectLkVehicleList(lkVehicle);
    }

    /**
     * 新增车型管理
     * 
     * @param lkVehicle 车型管理
     * @return 结果
     */
    @Override
    public int insertLkVehicle(LkVehicle lkVehicle)
    {
        return lkVehicleMapper.insertLkVehicle(lkVehicle);
    }

    /**
     * 修改车型管理
     * 
     * @param lkVehicle 车型管理
     * @return 结果
     */
    @Override
    public int updateLkVehicle(LkVehicle lkVehicle)
    {
        return lkVehicleMapper.updateLkVehicle(lkVehicle);
    }

    /**
     * 批量删除车型管理
     * 
     * @param ids 需要删除的车型管理ID
     * @return 结果
     */
    @Override
    public int deleteLkVehicleByIds(Long[] ids)
    {
        List<LkVehicle> vehicleList=lkVehicleMapper.selectLkVehicleListByIds(ids);
        for (LkVehicle lkVehicle : vehicleList) {
            if (StringUtils.isNoneBlank(lkVehicle.getVehicleImage())) {
                String[] vehicleImg=lkVehicle.getVehicleImage().split(",");
                for (String s : vehicleImg) {
                    String localPath = LuKeConfig.getProfile();
                    String filePath = localPath + StringUtils.substringAfter(s, Constants.RESOURCE_PREFIX);
                    FileUtils.deleteFile(filePath);
                }
            }
        }
        return lkVehicleMapper.deleteLkVehicleByIds(ids);
    }

    /**
     * 删除车型管理信息
     * 
     * @param id 车型管理ID
     * @return 结果
     */
    @Override
    public int deleteLkVehicleById(Long id)
    {
        return lkVehicleMapper.deleteLkVehicleById(id);
    }

    @Override
    public List<String> selectVehicleModelList() {
        return lkVehicleMapper.selectVehicleModelList();
    }

    @Override
    public List<String> selectVehicleColorList(String vehicleMode) {
        return lkVehicleMapper.selectVehicleColorList(vehicleMode);
    }

    @Override
    public LkVehicle selectLkVehicleByModel(String vehicleModel) {
        return lkVehicleMapper.selectLkVehicleByModel(vehicleModel);
    }


}
